package io.github.biezhi.adapterObject;

/**
 * 2. 对象适配器模式
 * 对象适配器模式通过组合的方式持有源接口（或具体类）的对象，并实现目标接口（或继承自目标抽象类）来完成适配。
 */

interface  TargetInterface {
    void request();
}

interface AdapteeInterface {
    void specificRequest();
}

class ConcreteAdapter implements AdapteeInterface {
    @Override
    public void specificRequest() {
        System.out.println("Adaptee: Handling specific request");
    }
}

class ObjectAdapter implements TargetInterface {
    private AdapteeInterface adaptee;

    public ObjectAdapter(AdapteeInterface adaptee) {
        this.adaptee = adaptee;
    }

    @Override
    public void request() {
        this.adaptee.specificRequest();
        System.out.println("Adapter: Additional processing after calling specific request");
    }
}

public class AdapterObject {
    public static void main(String[] args) {
        ObjectAdapter objectAdapter = new ObjectAdapter(new ConcreteAdapter());
        objectAdapter.request();
    }
}
